package com.aptemo.webetek.client.widgets.window;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class WindowContainer
		extends Composite implements ClickHandler
{
	private static WindowContainerUiBinder	uiBinder	= GWT.create(WindowContainerUiBinder.class);

	interface WindowContainerUiBinder extends UiBinder<Widget, WindowContainer>
	{
	}

	private HasWidgets	container;

	@UiField
	Label				titleField;

	@UiField
	Anchor				closeLink;

	@UiField
	VerticalPanel		decoreePanel;

	public WindowContainer(Widget widget)
	{
		initWidget(uiBinder.createAndBindUi(this));

		decoreePanel.add(widget);
		
		titleField.setText(widget.getTitle());
	}

	@UiHandler("closeLink")
	public void onClick(ClickEvent event)
	{
		container.clear();
	}

	public HasWidgets getDecoreePanel()
	{
		return decoreePanel;
	}

	public void go(HasWidgets container)
	{
		this.container = container;

		container.clear();
		container.add(this);
	}
	
	public Widget getWidget()
	{
		return decoreePanel.getWidget(0);
	}

}
